<?php
namespace Modules\BlogAdmin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\Admin\Http\Requests\CommonDeleteRequest;
use Modules\Admin\Http\Requests\CommonDeleteAllRequest;
use Modules\BlogAdmin\Models\BlogComment as BlogCommentModel;
use Modules\BlogAdmin\Models\BlogArticle as BlogArticleModel;
use Modules\Admin\Http\Controllers\CommonController;
class BlogCommentController extends CommonController
{
	/**
	 * @name  列表
	 */
    public function index()
    { 
        return view('blogadmin::blog_comment.index');
    }
	/**
	 * @name  列表数据
	 */
    public function data(Request $request)
    {
	    $model = BlogCommentModel::query();
		$params = $request->all();
		$model = query_condition($model,$params);
		if (!empty($params['title'])){
			$ids = BlogArticleModel::where('title','like','%' . $params['title'] . '%')->pluck('id')->toArray();
			$model->whereIn('blog_article_id',$ids);
		}
        $res = $model->with('article_to')
				->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray(); 
		$res['data'] = (new BlogCommentModel())->data_list($res['data']);	
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
	/**
	 * @name  删除数据处理
	 */
    public function destroy(CommonDeleteRequest $request)
    {
		return (new BlogCommentModel())->common_destroy($request->get('id'),route('blog_admin.comment.index'));  
    }
	/**
	 * @name  批量删除数据处理
	 */
    public function destroy_all(CommonDeleteAllRequest $request)
    {
		return (new BlogCommentModel())->common_destroy($request->get('ids'),route('blog_admin.comment.index'));  
    }
	
	
	
	
	
}
